package cz.cuni.amis.episodic.bayes.experiment;

import cz.cuni.amis.episodic.bayes.memories.IntervalSurpriseMemoryCreator;
import cz.cuni.amis.episodic.bayes.memories.MemoryCreationStrategy;
import cz.cuni.amis.episodic.bayes.memories.MemoryCreator;
import cz.cuni.amis.episodic.bayes.memories.MinimizeKLMemoryCreator;
import cz.cuni.amis.episodic.bayes.utils.DynamicNodeProperty;
import cz.cuni.amis.episodic.bayes.utils.MemoryChartCreator;
import cz.cuni.amis.episodic.bayes.utils.chart.GraphPaintingDevice;
import cz.cuni.amis.episodic.bayes.utils.chart.PngGraphDevice;
import cz.cuni.amis.episodic.dybanem.DBN;
import cz.cuni.amis.episodic.dybanem.RetrospectiveMemoriesCreator;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import smile.Network;

/**
 * Memory creation in two level model.
 * @author ik
 */
public class Experiment_3 {

    public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
        Network origNet = new Network();
        origNet.readFile("../datasets/3/em_03_learned.xdsl");

        // usual observations
        List<String> evidence = Arrays.asList("A", "A", "B", "A", "A", "B", "A", "A", "C", "A", "A", "B", "A", "A", "B", "A", "A", "C", "A", "A", "C");

        // observation with exception
        List<String> abnormalEvidence = new ArrayList<>(evidence);
        abnormalEvidence.set(18, "B");
        abnormalEvidence.set(19, "B");
        abnormalEvidence.set(20, "B");
        
        evidence = abnormalEvidence;
        
        DBN net = new DBN(origNet, evidence.size());

        String[] targets = new String[]{"O", "G1", "G2"};
        List<DynamicNodeProperty[]> res = Experiment_2.evolveOverTime(net, "O", evidence, targets);

        // draw default graphs      
        GraphPaintingDevice graphDevice = new PngGraphDevice("target/experiments/3/graphs/");
        MemoryChartCreator.createDefaultCharts(res, net, graphDevice);

        //MemoryCreator memoryCreator = new IntervalSurpriseMemoryCreator(graphDevice);
        //MemoryCreator memoryCreator = new MinimizeKLMemoryCreator(graphDevice);
        //RetrospectiveMemoriesCreator.createMemories(net, evidence, targets, 4, memoryCreator);//new MinimizeKLMemoryCreator()); 
        MemoryCreationStrategy.compare(evidence, net, targets, graphDevice);
    }
}
